import { countByStatus, countByType } from '@/services/ownCourse';
import type { Reducer, Effect } from 'umi';

export interface OwnCourse {
  status?: number;
  count?: number;
  countArray?: [];
  typeArray?: [];
  type?: number;
  name?: string;
  id?: number;
  duan?: string;
  startTime?: string;
  endTime?: string;
  teacherName?: string;
  currentStudentCount?: number;
  realName?: string;
  // duanList?: [],
  currentPage?: number;
  teacherId?: number;
  countNum?: number;
}
export interface PermissionModelType {
  namespace: string;
  state: OwnCourse;
  effects: {
    countByStatus: Effect;
    countByType: Effect;
  };
  reducers: {
    setState: Reducer<OwnCourse>;
  };
}
const OwnCourseModel: PermissionModelType = {
  namespace: 'ownCourse',

  state: {
    countArray: [],
    typeArray: [],
  },

  effects: {
    *countByStatus({ payload, callback }, { call, put }) {
      const response = yield call(countByStatus, payload);
      if (response.result === '200') {
        yield put({
          type: 'setState',
          payload: {
            countArray: response.result,
          },
        });
      }
      callback?.(response.result);
    },
    *countByType({ payload, callback }, { call, put }) {
      const response = yield call(countByType, payload);
      if (response.result === '200') {
        yield put({
          type: 'setState',
          payload: {
            typeArray: response.result,
          },
        });
      }
      callback?.(response.result);
    },
  },

  reducers: {
    setState(state, action) {
      return { ...state, ...action.payload };
    },
  },
};

export default OwnCourseModel;
